package com.songlanyun.modules.offlinegoods.exception;

import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.songlanyun.common.drive.IntegerEnum;

/**
 * 维护错误码之后也要维护错误描述
 * 1.错误码定义规则为5个数字
 * @author lijiahe 2023-02-11
 */
public enum OfflineGoodsTypeExceptionEnum implements IntegerEnum<Integer> {
    OFFLINE_GOODS_TYPE_NOT_EXISTS(22001, "线下商品类型不存在"),
    OFFLINE_GOODS_TYPE_REPEAT(22002, "类型名称重复"),
    OFFLINE_GOODS_TYPE_CANNOT_BE_DELETED(22003, "该分类已被商品使用，不可删除!"),
    OFFLINE_GOODS_TYPE_CANNOT_OPERATE(22004, "当前用户不是联盟商家，不能操作下线商品类型"),
    OFFLINE_GOODS_TYPE_SAFE(22005, "只能操作自己下线商品类型"),
    ;


    private Integer code;
    private String msg;

    OfflineGoodsTypeExceptionEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }


    public void setCode(Integer code) {
        this.code = code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    @JsonCreator
    public static OfflineGoodsTypeExceptionEnum getByCode(int code) {
        for (OfflineGoodsTypeExceptionEnum value : OfflineGoodsTypeExceptionEnum.values()) {
            if (Objects.equals(code, value.getCode())) {
                return value;
            }
        }
        return null;
    }
}
